<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!-- <button id="m-button">changeColor</button>

    <script>
    let mButton = document.querySelector('button');
    function randomColor(number) {
        return Math.floor(Math.random() * (number+1));

    }
    mButton.onclick = function() {
        let ranColor = `rgb(${randomColor(255)},${randomColor(255)},${randomColor(255)})`;
        document.body.style.backgroundColor = ranColor;
    }
    </script> -->

    <!-- 行内处理 -->
    <!-- <button onclick="changeColor()">点击换色</button>
    <script>
    function randomColor(number) {
        return Math.floor(Math.random() * (number+1));
    }
    function changeColor() {
        let bgColor = `rgb(${randomColor(255)},${randomColor(255)},${randomColor(255)})`
        document.body.style.backgroundColor = bgColor
    } -->

    <!-- 事件监听器 -->
    <!-- <button>changeColor</button>
    <script>
    let btn = document.querySelector('button');

    function randomNumber(number) {
        return Math.floor(Math.random()*(number+1));
    }
    function changeColor() {
        bgColor = `rgb(${randomNumber(255)},${randomNumber(255)},${randomNumber(255)})`
        document.body.style.backgroundColor = bgColor
    }
    btn.addEventListener('click',changeColor) -->

    <!-- 事件对象 -->
    <button>changeColor</button>
    <script>
    let btn = document.querySelector('button')
    function randomNumber(number) {
        return Math.floor(Math.random()*(number+1))
    }
    function changeColor(ev) {
        let bgColor = `rgb(${randomNumber(255)},${randomNumber(255)},${randomNumber(255)})`
        ev.target.style.backgroundColor = bgColor
        console.log('ev :', ev);
    }
    btn.addEventListener('click',changeColor)
    
    </script>
    </script>
    </script>
</body>
</html>